package com.shortvedio.user.api;

import com.shortvedio.base.context.BaseContext;
import com.shortvedio.user.model.dto.ChangePassword;
import com.shortvedio.user.model.dto.SUserInfoDto;
import com.shortvedio.user.model.dto.SUserLoginDto;
import com.shortvedio.user.service.UserService;
import com.shortvedio.base.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/creat")  //创建用户
    public Result creat(@RequestBody SUserLoginDto sUserLoginDto){
        Result stringResult = userService.creatUser(sUserLoginDto);
        return stringResult;
    }

    @PostMapping("change_user_info")//修改用户信息
    public Result changeUserInf(@RequestBody SUserInfoDto sUserInfoDto){
        //通过token获取到用户的id
        Long userIdToken = BaseContext.getCurrentId();
        Result sUserInfoResult = userService.changeUserInfo(sUserInfoDto,userIdToken);
        return sUserInfoResult;
    }

    @PostMapping("update_password")//更新用户密码
    public Result updatePassword(@RequestBody ChangePassword changePassword){
        Long userIdToken = BaseContext.getCurrentId();
        Result result = userService.updatePassword(changePassword, userIdToken);
        return result;
    }

}
